//
//  MyTreasureVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/29.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "MyTreasureVC.h"
#import "SYRequestAPI+Wode.h"
#import "MyTreasureObject.h"


@interface MyTreasureVC ()
@property (nonatomic, strong) MyTreasureObject *object;
@end

@implementation MyTreasureVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.navView];
    [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@50);
    }];
    
    [self.view addSubview:self.tableList];
    [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@100);
        make.right.equalTo(@0).offset(-100);
        make.top.equalTo(self->_navView.mas_bottom).offset(30);
        make.height.equalTo(@100);
    }];
    
    [self getWoDeCaiFuRequest];
}
- (WoDeNavView *)navView{
    if (!_navView) {
        WoDeNavView *topView = [[WoDeNavView alloc]init];
        topView.frame = CGRectMake(0, 0, self.view.frame.size.width,50);
        topView.delegate = self;
        topView.titleLabel.text = @"我的财富";
        topView.editeButton.hidden = YES;
        _navView = topView;
    }
    return _navView;
}

- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 144, self.view.frame.size.width-200, APP_HEIGHT-84) style:UITableViewStylePlain];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        [tableView registerClass:[MyTreasureCell class] forCellReuseIdentifier:@"MyTreasureCell"];
        tableView.layer.borderColor = LINCOLOR.CGColor;
        tableView.layer.borderWidth = 1;
        tableView.scrollEnabled = NO;
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableList = tableView;
    }
    return _tableList;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTreasureCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTreasureCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[MyTreasureCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyTreasureCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0) {
        cell.titleLabel.text = @"余额";
        cell.tf.placeholder = self->_object.fee;
    }else{
        cell.titleLabel.text = @"积分";
        cell.tf.placeholder = self->_object.integral;
    }

    cell.selected = NO;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了cell");
    if (indexPath.row == 0) {
        _balanceView = [[BalanceView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [self.view addSubview:self.balanceView];
        [_balanceView getBalanceDetailListRequest];
        [UIView animateWithDuration:0.5 animations:^{
            self->_balanceView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        }];
    }else{
        _jifenView = [[WoDeJiFenView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [self.view addSubview:self.jifenView];
        [_jifenView getBalanceDetailListRequest];
        [UIView animateWithDuration:0.5 animations:^{
            self->_jifenView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        }];
        
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    return view;
}
#pragma mark - 得到我的财富
- (void)getWoDeCaiFuRequest{
    NSDictionary *parama = @{};
    [SYRequestAPI sy_getFundServiceFundInfo:parama success:^(id  _Nonnull responseObject) {
        NSLog(@"得到我的财富 %@",responseObject);
        NSDictionary *dic =[responseObject objectForKey:@"data"];
        self->_object = [MyTreasureObject yy_modelWithJSON:dic];
        if (self->_object.fee.length == 0) {
            self->_object.fee = @"0";
        }
        if (self->_object.integral.length == 0) {
            self->_object.integral = @"0";
        }
        [self.tableList reloadData];
    } fail:^(NSError *error) {
        
    }];
}
@end
